import {Component, Input, ViewChild} from '@angular/core';
import {Platform} from "ionic-angular";

@Component({
  selector: 'g-default',
  templateUrl: 'g-default.html'
})
export class GDefaultComponent {

  imgSrc: string = ''
  @Input() type: string
  @Input() title: string = '暂无记录'
  @ViewChild('box') box: any
  wH: number
  elm: any
  pElm: any
  hide: boolean = true

  constructor(public platfrom: Platform) {
    this.wH = this.platfrom.height()
  }

  refreshSize() {
    let rect = this.pElm.getBoundingClientRect()
    let mH = rect.bottom - this.wH

    if (mH > -60) {
      let rate = 1 - Number((mH / (rect.height + 60)).toFixed(3))
      this.elm.style.transform = 'scale(' + rate + ')'
    }

    if (mH < 0) return
    let showH = rect.height - mH - 100
    this.elm.style.height = showH + 'px'
  }

  ngOnInit() {
    let config = {
      card: './assets/imgs/pic_card_none.png',
      coupon: './assets/imgs/pic_coupon_none.png',
      message: './assets/imgs/pic_message_none.png',
      product: './assets/imgs/pic_product_none.png',
      record: './assets/imgs/pic_record_none.png',
    }
    this.imgSrc = config[this.type]
  }

  ngAfterViewInit() {
    this.elm = this.box.nativeElement
    this.pElm = this.elm.parentElement.parentElement
    this.refreshSize()
  }

}
